package com.lee.enjoy221113_retrofit

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.Button
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Response
import java.io.IOException

class MainActivity : AppCompatActivity() {
    companion object{
        const val TAG ="MAINACT"
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        val enjoyRetrofit = EnjoyRetrofit.Builder().baseUrl("https://restapi.amap.com")
            .build()
        val weatherApi = enjoyRetrofit.create(WeatherApi::class.java)
        findViewById<Button>(R.id.btn_post).setOnClickListener {
            var call=weatherApi.postWeather("110101","ae6c53e2186f33bbf240a12d80672d1b")
            call.enqueue(object : Callback {
                override fun onFailure(call: Call?, e: IOException?) {
                    TODO("Not yet implemented")
                }

                override fun onResponse(call: Call?, response: Response?) {
                    var string = response?.body()?.string()
                    Log.i(TAG,"tianqi post=$string")
                }
            })
        }
        findViewById<Button>(R.id.btn_GET).setOnClickListener {

        }
    }
}